package com.enation.app.shop.front.api.repayrecord.service;

import com.enation.app.shop.front.api.creditrecord.entity.CreditRecord;
import com.enation.app.shop.front.api.repayrecord.entity.RepayRecord;
import com.enation.framework.database.IDaoSupport;
import com.enation.framework.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("repayRecordService")
public class RepayRecordManager implements IRepayRecordManager{
    @Autowired
    private IDaoSupport daoSupport;
    @Override
    public int Create(RepayRecord repayRecord) {
        this.daoSupport.insert("rbt_repayment_record",repayRecord);
        return 1;
    }

    @Override
    public List<RepayRecord> getByUserIdAndYearMonth(Integer userid, String year, String month) {
        String sql="";
        if (StringUtil.isEmpty(month)){
            sql="select * from rbt_repayment_record where user_id=?  AND  year(create_at)='"+year+"' order by create_at desc";
        }else {
            sql="select * from rbt_repayment_record where user_id=?  AND  year(create_at)='"+year+"' and  month(create_at)='"+month+"' order by create_at desc";
        }
        System.out.println(sql);
        List<RepayRecord> RepayRecords=daoSupport.queryForList(sql,RepayRecord.class,userid);
        int i=1;
        return RepayRecords;
    }
}
